import 'package:flutterclue/mvp/mode/base_mode.dart';
import 'package:flutter/material.dart';

abstract class HttpInterface {
  ValueChanged<String> onSelect;

  Future<BaseBean> get(
      {String url,
      Map<String, Object> headers,
      Map<String, Object> params,
      onSelect});

  Future<BaseBean> post(
      {String url,
      Map<String, Object> headers,
      Map<String, Object> params,
      onSelect});
}

/**
 * 枚举用不到了
 */
//enum HttpType { dio, http }

///工厂模式改成策略模式
class HttpFactory {
  static HttpInterface _httpInterface;
  static HttpFactory _httpFactory = new HttpFactory();

  static HttpFactory getHttpInstance(HttpInterface httpInterface) {
    _httpInterface = httpInterface;
    return _httpFactory;
  }

  ///post请求
  Future<BaseBean> postData(
      {String url,
      Map<String, Object> headers,
      Map<String, Object> params,
      ValueChanged<String> error}) {
    return _httpInterface.post(
        url: url, headers: headers, params: params, onSelect: error);
  }
}
